package com.yanqu.road.server.cmd.wingroom.watchplayer;

import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.pb.wingroom.WingRoomProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.manger.wingroom.WingRoomMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

/**
 * @author ：zfr
 * @date ：2022/2/23 14:11
 */
@Cmd(code = GameProtocol.S_WING_ROOM_CROSS_WATCH_REQ, desc = "跨服来拜访厢房")
public class CrossWatchWingRoomCmd implements Command {
    private long originPlayerUserId;
    private long originPlayerServerId;
    private long watchPlayerUserId;
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        WingRoomProto.CrossWatchOtherPlayerReqMsg msg = WingRoomProto.CrossWatchOtherPlayerReqMsg.parseFrom(packet.getBytes());
        originPlayerServerId = msg.getOriginServerId();
        originPlayerUserId = msg.getOriginPlayerId();
        watchPlayerUserId = msg.getWatchPlayerId();

        WingRoomProto.CrossWatchOtherPlayerRespMsg.Builder respCrossMsg = WingRoomProto.CrossWatchOtherPlayerRespMsg.newBuilder();
        respCrossMsg.setRespMsg(WingRoomMgr.getVisitMsg(watchPlayerUserId));
        respCrossMsg.setOriginPlayerServerId(originPlayerServerId);
        respCrossMsg.setOriginPlayerUserId(originPlayerUserId);
        //命盘是否解锁
        respCrossMsg.setChakraOpenFlag(SystemOpenMgr.checkSystemOpen(watchPlayerUserId, eSystemId.Chakra.getValue()));

        YanQuMessage message = YanQuMessageUtils.buildMessage(CrossProtocol.C_WING_ROOM_VISIT_OTHER_PLAYER_RESP, respCrossMsg);
        GamePlayerMgr.sendPacket(0, message);
    }
}
